import { request } from "@/utils/service"
import * as Project from "@/api/project/types/project"

/**
 * 增
 * @param data 请求参数
 * @constructor
 */
export function AddProjectApi(data: Project.IAddProjectRequestData) {
  return request<Project.AddResponseData>({
    url: "project/addOne",
    method: "post",
    data
  })
}

/**
 * 删
 * @param id 项目id
 * @constructor
 */
export function DeleteProjectApi(id: string) {
  return request<Project.DeleteResponseData>({
    url: "project/deleteOne",
    method: "delete",
    params: { id }
  })
}

/**
 * 改
 * @param data
 * @constructor
 */
export function UpdateProjectApi(data: Project.IUpdateRequestData) {
  return request<Project.UpdateResponseData>({
    url: "project/updateOne",
    method: "put",
    data
  })
}

/**
 * 条件查询+分页查询
 * @param data
 * @constructor
 */
export function FindProjectByCondApi(data: Project.IGetProjectRequestData, item: number) {
  return request<Project.GetProjectResponseData>({
    url: "project/getList?item=" + item,
    method: "post",
    data
  })
}
export function GetProjectIdAndNameList(data: { name: string; departmentId: number | undefined }) {
  return request<Project.GetProjectIdAndNameResponseData>({
    url: "project/getIdAndNameList",
    method: "post",
    data
  })
}

export function ExportStatisticsExcelApi(data: Project.IExportStatisticsExcelRequestData) {
  return request<{ blob: Blob; fileName: string }>({
    url: "project/exportStatisticsExcel",
    method: "post",
    responseType: "blob",
    data
  })
}

/**
 * 获取添加模板
 */
export function getExcelTemplateApi() {
  return request<{ blob: Blob; fileName: string }>({
    url: `project/getTemplate`,
    responseType: "blob",
    method: "get"
  })
}
